<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>医疗管家</title>
    <meta name="description" content="医疗管家">
    <meta name="keywords" content="医疗管家">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<style>
    .content{width:100%;display:flex;border-bottom:1px #ddd solid; }
    .content .head{width:90px;height:60px;background-color:#f1f1f1;text-align:center;line-height:60px;}
    .sex span{margin-left:20px;line-height:60px;}
    .active{color:red;background-color:#f1f1f1;}
</style>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>预约管理<small>检查项管理</small></h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>预约管理</el-breadcrumb-item>
            <el-breadcrumb-item>检查项管理</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">

        <div class="box">
            <div class="filter-container">
                <div class="el-table el-table--fit el-table--enable-row-transition" style="width: 100%;">
                    <div class="el-table__body-wrapper is-scrolling-none" style="margin-bottom: 10px">
                        <div class="el-table__column-resize-proxy" style="display: none;"></div>
                        <el-input placeholder="项目编码/项目名称" v-model="pagination.queryString" style="width: 200px;"
                                  class="filter-item"></el-input>
                        <el-button @click="findPage()" class="dalfBut">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                    </div>
                    <div class="content" >
                        <div class="head">性别</div>
                        <div class="sex" v-for="(item,index) in exList" :key="index">
                            <span :class="{active:index==isactive}"  @click="sex(item,index)">{{item}}</span>
                        </div>
                    </div>
                    <div class="content" >
                        <div class="head">年龄</div>
                        <div class="sex" v-for="(item,index) in ageList" :key="index">
                            <span :class="{active:index==isactive1}"  @click="age(item,index)">{{item}}</span>
                        </div>
                    </div>
                    <div class="content" >
                        <div class="head">注册时间</div>
                        <div class="sex" v-for="(item,index) in regList" :key="index">
                            <span :class="{active:index==isactive2}"  @click="reg(item,index)">{{item}}</span>
                        </div>
                    </div>

                    <el-table size="small" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="index" align="center" label="序号"></el-table-column>
                        <el-table-column prop="name" label="项目名称" align="center"></el-table-column>
                        <el-table-column label="适用性别" align="center">
                            <template slot-scope="scope">
                                <span>{{ scope.row.sex}}</span>
                            </template>
                        </el-table-column>
                        <el-table-column prop="idcard" label="身份证号" align="center"></el-table-column>
                        <el-table-column prop="phonenumber" label="电话号码" align="center"></el-table-column>
                        <el-table-column prop="regtime" label="注册时间" align="center"></el-table-column>
                        <el-table-column prop="email" label="邮箱" align="center"></el-table-column>
                        <el-table-column prop="birthday" label="出生日期" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                                class="pagiantion"
                                @current-change="handleCurrentChange"
                                :current-page="pagination.currentPage"
                                :page-size="pagination.pageSize"
                                layout="total, prev, pager, next, jumper"
                                :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- add添加  -->
                    <div>
                        <el-dialog title="会员添加" :visible.sync="dialogFormVisible">
                            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="90px" class="demo-ruleForm">
                                <el-form-item label="名字" prop="name">
                                    <el-input v-model="formData.name"></el-input>
                                </el-form-item>
                                <el-form-item label="性别" prop="sex">
                                <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
                                    <el-option label="不限" value="不限"></el-option>
                                    <el-option label="男" value="男"></el-option>
                                    <el-option label="女" value="女"></el-option>
                                </el-select>
                              </el-form-item>
                                <el-form-item label="身份证" prop="idcard">
                                    <el-input v-model="formData.idcard"></el-input>
                                </el-form-item>
                                <el-form-item label="电话" prop="phonenumber">
                                    <el-input v-model="formData.phonenumber"></el-input>
                                </el-form-item>
                                <el-form-item label="注册时间" prop="regtime">
                                    <el-input v-model="formData.regtime"></el-input>
                                </el-form-item>
                                <el-form-item label="密码" prop="password">
                                    <el-input v-model="formData.password"></el-input>
                                </el-form-item>
                                <el-form-item label="邮件" prop="email">
                                    <el-input v-model="formData.email"></el-input>
                                </el-form-item>
                                <el-form-item label="出生日期" prop="birthday">
                                    <el-input v-model="formData.birthday"></el-input>
                                </el-form-item>
                                <el-form-item label="描述" prop="remark">
                                    <el-input v-model="formData.remark"></el-input>
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" @click=" handleAdd('ruleForm')">立即创建</el-button>
                                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                                </el-form-item>
                            </el-form>
                        </el-dialog>
                    </div>
                  <!--  会员编辑  -->
                    <div>
                        <el-dialog title="会员编辑" :visible.sync="dialogFormVisible4Edit">
                            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
                                <el-form-item label="名字" prop="name">
                                    <el-input v-model="formData.name"></el-input>
                                </el-form-item>
                                <el-form-item label="性别" prop="sex">
                                    <el-select v-model="ruleForm.region" placeholder="请选择活动区域">
                                        <el-option label="不限" value="不限"></el-option>
                                        <el-option label="男" value="男"></el-option>
                                        <el-option label="女" value="女"></el-option>
                                    </el-select>
                                </el-form-item>
                                <el-form-item label="身份证" prop="idcard">
                                    <el-input v-model="formData.idcard"></el-input>
                                </el-form-item>
                                <el-form-item label="电话" prop="phonenumber">
                                    <el-input v-model="formData.phonenumber"></el-input>
                                </el-form-item>
                                <el-form-item label="注册时间" prop="regtime">
                                    <el-input v-model="formData.regtime"></el-input>
                                </el-form-item>
                                <el-form-item label="密码" prop="password">
                                    <el-input v-model="formData.password"></el-input>
                                </el-form-item>
                                <el-form-item label="邮件" prop="email">
                                    <el-input v-model="formData.email"></el-input>
                                </el-form-item>
                                <el-form-item label="出生日期" prop="birthday">
                                    <el-input v-model="formData.birthday"></el-input>
                                </el-form-item>
                                <el-form-item label="描述" prop="remark">
                                    <el-input v-model="formData.remark"></el-input>
                                </el-form-item>
                                <el-form-item>
                                    <el-button type="primary" @click=" handleAdd('ruleForm')">立即创建</el-button>
                                    <el-button @click="resetForm('ruleForm')">重置</el-button>
                                </el-form-item>
                            </el-form>
                        </el-dialog>
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data:{
            isactive:0,
            isactive1:0,
            isactive2:0,
            pagination: {//分页相关模型数据
                currentPage: 1,//当前页码
                pageSize:10,//每页显示的记录数
                total:0,//总记录数
                queryString:null,//查询条件
                age:'不限',
                reg:'不限',
                sex:'不限',
            },
            dataList: [], //当前页要展示的分页列表数据
            exList:['不限','男','女'],
            ageList:['不限','0-19','20-29','30-39','40-49','50-59','60以上'],
            regList:['不限','2003','2004','2005','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021'],
            formData: {},//表单数据
            dialogFormVisible: false,//增加表单是否可见
            dialogFormVisible4Edit:false,//编辑表单是否可见
            rules: { //校验规则
                phonenumber: [{
                    required: true,
                    message: '项目编码为必填项',
                    trigger: 'blur'
                }, {min: 11, max: 11, message: '长度在11个字符', trigger: 'blur'}],
                name: [{
                    required: true,
                    message: '项目名称为必填项',
                    trigger: 'blur'
                }]
            },
        },
        //钩子函数，VUE对象初始化完成后自动执行
        created() {
          this.listPage();
        },
        methods: {
            ruleForm(){

            },
            sex(value,index){
                this.isactive=index;
                this.pagination.sex = value;
                this.listPage()
            },
            listPage(){
                axios.post("http://localhost:9002/member/list",this.pagination).then(resp=>{
                    this.dataList = resp.data.rows;
                    this.pagination.total = resp.data.total;
                })

            },
            //编辑检查项
            handleEdit() {

            },
            //添加检查项
            handleAdd () {
                this.$refs['dataAddForm'].validate(valid => {
                    if (valid) {
                        axios.post("http://localhost:9002/member/save", this.formData).then(resp => {
                            if (resp.data.flag) {
                                this.$message.success(resp.data.message);
                                this.dialogFormVisible = false;
                                this.listPage();
                            } else {
                                this.$message.error(resp.data.message);
                            }
                        })
                    } else {
                        this.$message.error("表单校验不成功");
                    }
                })
            },
            //分页查询
            findPage() {
                this.listPage()
            },
            //重置表单
            resetForm() {

            },
            //弹出添加窗口
            handleCreate() {
               this.dialogFormVisible = true;
            },
            //弹出编辑窗口
            handleUpdate(row) {
              this.dialogFormVisible4Edit = true;
            },
            //切换页码显示分页信息
            handleCurrentChange(currentPage) {
                this.pagination.currentPage = currentPage;
                this.listPage()

            },
            // 删除检查项
            handleDelete(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    axios.delete(`http://localhost:9002/member/remove/${row.id}`).then(resp=>{
                        if (resp.data.flag) {
                            this.$message({
                                type: 'success',
                                message: resp.data.message
                            });
                            this.listPage();
                        } else {
                            this.$message.error(resp.data.message)
                        }
                    })
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });


            },
            age(value,index){
                this.isactive1=index;
                this.pagination.age = value;
                this.listPage();
            },
            reg(value,index){
                this.isactive2 =index;
               this.pagination.reg = value;
               this.listPage();
            }
        }
    })
</script>
</html>
